<?php

namespace App\Http\Controllers\Admin\Api;

use App\Facades\UserService;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Cache;
use Illuminate\Http\Request;
use Redis;

class ConfigController extends Controller
{
    public function storePrice(Request $request)
    {
        $rules = [
            'price' => 'required|numeric|price',
        ];
        $this->validate($request, $rules);

        UserService::hasPermission(['superadmin']);
        Redis::set('price', $request->price);
        Redis::bgsave();
        return formatJsonResponse();
    }

    public function storeBindMessage(Request $request)
    {
        $rules = [
            'content1' => 'required',
            'content2' => 'required',
            'content3' => 'required',
        ];
        $this->validate($request, $rules);

        UserService::hasPermission(['admin']);
        Redis::set('bindMessage', json_encode(['content1' => $request->content1, 'content2' => $request->content2, 'content3' => $request->content3]));
        Redis::command('bgsave');
        return formatJsonResponse();
    }
}
